package com.dengqi.mymodule.activity.memory;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.dengqi.mymodule.BaseActivity;
import com.dengqi.mymodule.R;
import com.module.imagelib.glide.GlideApp;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dell on 2018/7/2
 */

public class MemoryActivity extends BaseActivity {

    ImageView imageView;
    String url = "http://t1.mmonly.cc/uploads/tu/201709/9999/01a9e54720.jpg";
    String urlFormat = "http://t1.mmonly.cc/uploads/tu/sm/201602/19/%s.jpg";
    List<String> strs;
    int count = 100;
    int i = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_memory);
        initData();
        imageView = findViewById(R.id.imageView);
        GlideApp.with(this.getApplicationContext()).load(url).skipMemoryCache(true).into(imageView);
//        ImageLoader_v1.getInstance().load(this, url).cache().progress().into(imageView);
//        SPHelper.save(this, "memory", "activity_singleItem", "haha");

    }

    private void initData() {
        strs = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            strs.add(String.format(urlFormat, i + 1));
        }

    }


    public void onBtn1(View view) {
        //跳过缓存5M左右就回收了
        GlideApp.with(this.getApplicationContext()).load(strs.get(i)).skipMemoryCache(true).into(imageView);
        i = i + 1;
        i = i % count;
    }

    @Override
    protected void onDestroy() {
        //效果拔群
        GlideApp.get(this.getApplicationContext()).clearMemory();
        super.onDestroy();
    }
}
